/**
 * Created by Administrator on 2017/3/27 0027.
 */
var Page0={
    create:function () {
        var page={};
        var bool_down;
        var sx;
        var mouseSX;
        var lastSX;
        var delta;
        var downName='';
        page.bool_touch=true;
        page.scrolling=false;
        // document.addEventListener('mousedown',mouseHandler);
        // document.addEventListener('touchstart',touchHandler);

        page.ui=new PIXI.DisplayObjectContainer();
        page.scroll=new PIXI.DisplayObjectContainer();
        page.scroll.name='scroll';

        // scroll.x=-2000;
        var bgCon=new PIXI.DisplayObjectContainer();
        bgCon.interactive=true;
        page.ui.addChild( page.scroll);
        for(var i=1;i<8;i++)
        {
            var bg=new PIXI.Sprite(resource['assets/images/bg1_0'+ i.toString()+'.png'].texture);
            bg.x=(i-1)*1000;
            bgCon.addChild(bg);
        }
        page.scroll.addChild(bgCon);

        var t1=new PIXI.Sprite(resource['assets/images/t1.png'].texture);
        t1.x=402;
        t1.y=117;
        page.scroll.addChild(t1);
        TweenMax.to(t1,1.5,{x:402+10,repeat:-1,yoyo:true,repeatDelay:0.5,ease:Linear.easeNone});

        var t2=new PIXI.Sprite(resource['assets/images/t2.png'].texture);
        t2.x=984;
        t2.y=245;
        page.scroll.addChild(t2);
        TweenMax.to(t2,1.5,{y:245+5,repeat:-1,yoyo:true,repeatDelay:0.5,ease:Cubic.easeInOut});

        var arr_texture=[];
        console.log(resource)
        for(var i=0;i<51;i++)
        {
            if(i<10)
            {
                var texture = resource['assets/images/One/One.000'+i.toString()+'.png'].texture;
            }
            else
            {
                var texture = resource['assets/images/One/One.00'+i.toString()+'.png'].texture;
            }
            arr_texture.push(texture);
        }
        var mc_t0=new PIXI.extras.AnimatedSprite(arr_texture);
        mc_t0.animationSpeed=0.25;
        mc_t0.gotoAndPlay(1);
        mc_t0.x=113;
        page.scroll.addChild(mc_t0);


        // var t0=new PIXI.Sprite(resource['assets/images/t0.png'].texture);
        // t0.x=122;
        // t0.y=49;
        // page.scroll.addChild(t0);
        // var t0_glow=new PIXI.Sprite(resource['assets/images/t0_glow.png'].texture);
        // t0_glow.x=122;
        // t0_glow.y=49;
        // page.scroll.addChild(t0_glow);
        // var t0_mask=new PIXI.Graphics();
        // t0_mask.beginFill();
        // t0_mask.drawRect(0,0,1080,498);
        // //t0_mask.width=1
        // t0_mask.endFill();
        // t0_mask.x=-974;
        // t0_mask.y=13;
        // page.scroll.addChild(t0_mask);
        // t0_glow.mask=t0_mask;
        // TweenMax.to(t0_mask,15,{x:888,repeat:-1,repeatDelay:5,ease:Linear.easeNone});

        var line=new PIXI.Sprite(resource['assets/images/line.png'].texture);
        line.x=1754;
        line.y=107;
        page.scroll.addChild(line);
        TweenMax.to(line,2.5,{x:1754-10,y:107+10,repeat:-1,yoyo:true,repeatDelay:0.5,ease:Cubic.easeInOut});

        var line_glow=new PIXI.Sprite(resource['assets/images/line_glow.png'].texture);
        // line_glow.x=1744;
        // line_glow.y=100;
        line_glow.x=1754;
        line_glow.y=107;
        page.scroll.addChild(line_glow);
        TweenMax.to(line_glow,2.5,{x:1754-10,y:107+10,repeat:-1,yoyo:true,repeatDelay:0.5,ease:Cubic.easeInOut});

        var line_mask=new PIXI.Graphics();
        line_mask.beginFill();
        line_mask.drawRect(0,0,62,498);
        line_mask.endFill();
        line_mask.x=1681;
        line_mask.y=81;
        page.scroll.addChild(line_mask);
        line_glow.mask=line_mask;
        TweenMax.to(line_mask,15,{x:4502,repeat:-1,repeatDelay:5,ease:Linear.easeNone});

        var tip0=new PIXI.Sprite(resource['assets/images/tip0.png'].texture);
        tip0.anchor.set(0.5);
        tip0.x=2007;
        tip0.y=207;
        page.scroll.addChild(tip0);
        TweenMax.to(tip0.scale,0.7,{x:0.9,y:0.9,repeat:-1,yoyo:true,ease:Cubic.easeInOut});
        var arr_texture1=[];
        for(var i=0;i<51;i++)
        {
            if(i<10)
            {
                var texture1 = resource['assets/images/LSJ/LSJ.000'+i.toString()+'.png'].texture;
            }
            else
            {
                var texture1 = resource['assets/images/LSJ/LSJ.00'+i.toString()+'.png'].texture;
            }

            arr_texture1.push(texture1);
        }
        var mc_lsj=new PIXI.extras.AnimatedSprite(arr_texture1);
        mc_lsj.animationSpeed=0.4;
        mc_lsj.gotoAndPlay(1);
        mc_lsj.x=1436;
        page.scroll.addChild(mc_lsj);
        TweenMax.to(mc_lsj,2,{y:10,repeat:-1,yoyo:true,ease:Cubic.easeInOut});

        var tip1=new PIXI.Sprite(resource['assets/images/tip1.png'].texture);
        tip1.anchor.set(0.5);
        tip1.x=2108;
        tip1.y=152;
        tip1.rotation=-15*Math.PI/180
        page.scroll.addChild(tip1);
        TweenMax.to(tip1,3,{rotation:15*Math.PI/180,repeat:-1,yoyo:true,ease:Cubic.easeInOut});

        var tip2=new PIXI.Sprite(resource['assets/images/tip2.png'].texture);
        tip2.anchor.set(0.5);
        tip2.x=2251;
        tip2.y=361;
        tip2.rotation=-10*Math.PI/180
        page.scroll.addChild(tip2);
        TweenMax.to(tip2,5,{rotation:10*Math.PI/180,repeat:-1,yoyo:true,ease:Cubic.easeInOut});

        var tip3=new PIXI.Sprite(resource['assets/images/tip3.png'].texture);
        tip3.anchor.set(0.5);
        tip3.x=2682;
        tip3.y=288;
        tip3.rotation=0*Math.PI/180
        page.scroll.addChild(tip3);
        TweenMax.to(tip3,3.5,{rotation:0*Math.PI/180,y:288+30,repeat:-1,yoyo:true,ease:Cubic.easeInOut});

        var tip4=new PIXI.Sprite(resource['assets/images/tip4.png'].texture);
        tip4.anchor.set(0.5);
        tip4.x=2771;
        tip4.y=271;
        tip4.rotation=0*Math.PI/180
        page.scroll.addChild(tip4);
        TweenMax.to(tip4,2.5,{rotation:0*Math.PI/180,y:271-30,repeat:-1,yoyo:true,ease:Cubic.easeInOut});

        var tip5=new PIXI.Sprite(resource['assets/images/tip5.png'].texture);
        tip5.anchor.set(0.5);
        tip5.x=2923;
        tip5.y=319;
        tip5.rotation=0*Math.PI/180
        page.scroll.addChild(tip5);
        TweenMax.to(tip5,2.5,{rotation:0*Math.PI/180,x:2923+30,repeat:-1,yoyo:true,ease:Cubic.easeInOut})

        var tip6=new PIXI.Sprite(resource['assets/images/tip6.png'].texture);
        tip6.anchor.set(0.5);
        tip6.x=3475;
        tip6.y=193;
        tip6.rotation=0*Math.PI/180
        page.scroll.addChild(tip6);
        TweenMax.to(tip6,2.5,{rotation:0*Math.PI/180,y:193-30,repeat:-1,yoyo:true,ease:Cubic.easeInOut});

        var tip7=new PIXI.Sprite(resource['assets/images/tip7.png'].texture);
        tip7.anchor.set(0.5);
        tip7.x=3623;
        tip7.y=295;
        tip7.rotation=0*Math.PI/180
        page.scroll.addChild(tip7);
        TweenMax.to(tip7,2,{rotation:20*Math.PI/180,y:295+15,repeat:-1,yoyo:true,ease:Cubic.easeInOut});

        var tip8=new PIXI.Sprite(resource['assets/images/tip8.png'].texture);
        tip8.anchor.set(0.5);
        tip8.x=3720;
        tip8.y=94;
        tip8.rotation=0*Math.PI/180
        page.scroll.addChild(tip8);
        TweenMax.to(tip8,2,{rotation:-20*Math.PI/180,y:94+15,repeat:-1,yoyo:true,ease:Cubic.easeInOut});

        var tip9=new PIXI.Sprite(resource['assets/images/tip9.png'].texture);
        tip9.anchor.set(0.5);
        tip9.x=3808;
        tip9.y=183;
        tip9.rotation=0*Math.PI/180
        page.scroll.addChild(tip9);
        TweenMax.to(tip9,3,{rotation:-0*Math.PI/180,y:183+45,repeat:-1,yoyo:true,ease:Cubic.easeInOut});

        var tip10=new PIXI.Sprite(resource['assets/images/tip10.png'].texture);
        tip10.anchor.set(0.5);
        tip10.x=4417;
        tip10.y=268;
        tip10.rotation=0*Math.PI/180
        page.scroll.addChild(tip10);
        TweenMax.to(tip10,2.5,{rotation:-30*Math.PI/180,y:268+15,repeat:-1,yoyo:true,ease:Cubic.easeInOut});

        // var i0=new PIXI.Sprite(resource['assets/images/i0.png'].texture);
        // i0.anchor.set(0.5);
        // i0.x=1668;
        // i0.y=637;
        // page.scroll.addChild(i0);
        // TweenMax.to(i0.scale,1,{x:0.95,y:0.95,repeat:-1,yoyo:true,repeatDelay:0.0,ease:Linear.easeNone});

        var i1=new PIXI.Sprite(resource['assets/images/i1.png'].texture);
        i1.anchor.set(0.5);
        i1.interactive=true;
        i1.x=2163;
        i1.y=256;
        page.scroll.addChild(i1);
        TweenMax.to(i1,1,{y:256-10,repeat:-1,yoyo:true,repeatDelay:0.0,ease:Cubic.easeInOut});

        var i2=new PIXI.Sprite(resource['assets/images/i2.png'].texture);
        i2.anchor.set(0.5);
        i2.x=2513;
        i2.y=226;
        page.scroll.addChild(i2);
        TweenMax.to(i2,1.5,{x:2513-5,repeat:-1,yoyo:true,repeatDelay:0.0,ease:Cubic.easeInOut});

        var i3=new PIXI.Sprite(resource['assets/images/i3.png'].texture);
        i3.anchor.set(0.5);
        i3.x=2881;
        i3.y=232;
        page.scroll.addChild(i3);
        TweenMax.to(i3,2.5,{y:232+15,repeat:-1,yoyo:true,repeatDelay:0.0,ease:Cubic.easeInOut});

        var i4=new PIXI.Sprite(resource['assets/images/i4.png'].texture);
        i4.anchor.set(0.5);
        i4.x=3509;
        i4.y=297;
        page.scroll.addChild(i4);
        TweenMax.to(i4,3.5,{x:3509-50,repeat:-1,yoyo:true,repeatDelay:0.0,ease:Cubic.easeInOut});

        var i5=new PIXI.Sprite(resource['assets/images/i5.png'].texture);
        i5.anchor.set(0.5);
        i5.x=3572;
        i5.y=225;
        page.scroll.addChild(i5);
        TweenMax.to(i5.scale,2.0,{x:0.9,y:0.9,repeat:-1,yoyo:true,repeatDelay:0.0,ease:Cubic.easeInOut});

        var i6=new PIXI.Sprite(resource['assets/images/i6.png'].texture);
        i6.anchor.set(0.5);
        i6.x=4275;
        i6.y=222;
        page.scroll.addChild(i6);
        TweenMax.to(i6,2.0,{y:222+30,repeat:-1,yoyo:true,repeatDelay:0.0,ease:Cubic.easeInOut});

        var img3=new PIXI.Sprite(resource['assets/images/image3.png'].texture);
        img3.anchor.set(0.0);
        img3.x=4577;
        img3.y=97;
        page.scroll.addChild(img3);

        // var t3=new PIXI.Sprite(resource['assets/images/t3.png'].texture);
        // t3.x=5134;
        // t3.y=108;
        // page.scroll.addChild(t3);
        // var t3_glow=new PIXI.Sprite(resource['assets/images/t3_glow.png'].texture);
        // t3_glow.x=5134;
        // t3_glow.y=108;
        // page.scroll.addChild(t3_glow);
        // var t3_mask=new PIXI.Graphics();
        // t3_mask.beginFill();
        // t3_mask.drawRect(0,0,1080,498);
        // t3_mask.endFill();
        // t3_mask.x=3996;
        // t3_mask.y=0;
        // page.scroll.addChild(t3_mask);
        // t3_glow.mask=t3_mask;
        // TweenMax.to(t3_mask,15,{x:5690,repeat:-1,repeatDelay:1,ease:Linear.easeNone});
        for(var i=0;i<1;i++)
        {
            var tip_a=new PIXI.Sprite(resource['assets/images/tip_right.png'].texture);
            tip_a.anchor.set(0.5);
            tip_a.scale.x=tip_a.scale.y=0.5;
            tip_a.x=1000+1700*i;
            tip_a.y=512;
            page.scroll.addChild(tip_a);
            TweenMax.to(tip_a,1,{x:tip_a.x+20,yoyo:true,repeat:-1,alpha:0.6,ease:Cubic.easeInOut});
        }


        var mc_t1=new PIXI.extras.AnimatedSprite(arr_texture);
        mc_t1.animationSpeed=0.3;
        mc_t1.gotoAndPlay(1);
        mc_t1.scale.x=mc_t1.scale.y=0.75;
        mc_t1.x=5125;
        mc_t1.y=75;
        page.scroll.addChild(mc_t1);

        var t4=new PIXI.Sprite(resource['assets/images/t4.png'].texture);
        t4.x=5466;
        t4.y=171;
        page.scroll.addChild(t4);
        TweenMax.to(t4,1.5,{y:171+10,yoyo:true,repeat:-1,repeatDelay:0.5,ease:Cubic.easeInOut});

        var t5=new PIXI.Sprite(resource['assets/images/t5.png'].texture);
        t5.x=5959;
        t5.y=110;
        page.scroll.addChild(t5);

        var t6=new PIXI.Sprite(resource['assets/images/t6.png'].texture);
        t6.x=5959;
        t6.y=207;
        page.scroll.addChild(t6);
        t6.interactive=true;
        t6.on('pointertap',tipDownHandler)

        var b0=new PIXI.Sprite(resource['assets/images/b0.png'].texture);
        b0.anchor.set(0.5);
        b0.x=2442;
        b0.y=280;
        page.scroll.addChild(b0);
        var b0_glow=new PIXI.Sprite(resource['assets/images/b0_glow.png'].texture);
        b0_glow.interactive=true;
        b0_glow.name='b0';
        // b0_glow.on('pointerdown',bDownHandler);
        b0_glow.on('pointermove',bMoveHandler);
        b0_glow.on('pointerup',bUpHandler);
        b0_glow.on('pointertap',bDownHandler);
        b0_glow.anchor.set(0.5);
        b0_glow.x=2442;
        b0_glow.y=280;
        b0_glow.alpha=0;
        page.scroll.addChild(b0_glow);
        TweenMax.to(b0_glow,2,{alpha:1,yoyo:true,repeat:-1,ease:Cubic.easeInOut,repeatDelay:0.5});

        var b1=new PIXI.Sprite(resource['assets/images/b1.png'].texture);
        b1.anchor.set(0.5);
        b1.x=3162;
        b1.y=289;
        page.scroll.addChild(b1);
        var b1_glow=new PIXI.Sprite(resource['assets/images/b1_glow.png'].texture);
        b1_glow.interactive=true;
        b1_glow.name='b1';
        // b1_glow.on('pointerdown',bDownHandler);
        b1_glow.on('pointermove',bMoveHandler);
        b1_glow.on('pointerup',bUpHandler);
        b1_glow.on('pointertap',bDownHandler);
        b1_glow.anchor.set(0.5);
        b1_glow.x=3162;
        b1_glow.y=289;
        b1_glow.alpha=1;
        page.scroll.addChild(b1_glow);
        TweenMax.to(b1_glow,2,{alpha:0,yoyo:true,repeat:-1,ease:Cubic.easeInOut,repeatDelay:0.5});

        var b2=new PIXI.Sprite(resource['assets/images/b2.png'].texture);
        b2.anchor.set(0.5);
        b2.x=4030;
        b2.y=247
        page.scroll.addChild(b2);
        var b2_glow=new PIXI.Sprite(resource['assets/images/b2_glow.png'].texture);
        b2_glow.interactive=true;
        b2_glow.name='b2';
        // b2_glow.on('pointerdown',bDownHandler);
        b2_glow.on('pointermove',bMoveHandler);
        b2_glow.on('pointerup',bUpHandler);
        b2_glow.on('pointertap',bDownHandler);
        b2_glow.anchor.set(0.5);
        b2_glow.x=4030;
        b2_glow.y=247;
        b2_glow.alpha=1;
        page.scroll.addChild(b2_glow);
        TweenMax.to(b2_glow,2,{alpha:0,yoyo:true,repeat:-1,ease:Cubic.easeInOut,repeatDelay:0.5});

        page.scroll.addChild(i2);

        var logo=new PIXI.Sprite(resource['assets/images/tiplogo.png'].texture);
        logo.x=6275;
        logo.y=310;
        page.scroll.addChild(logo);

        //var cover=new PIXI.Graphics();
        //cover.beginFill(0x0,0.5);
        //cover.drawRect(1136,540);
        //page.ui.addChild(cover);
        //cover.interactive=true;

        bgCon.on('pointerdown',downHandler);
        bgCon.on('pointermove',moveHandler);
        bgCon.on('pointerup',upHandler);
        var bb_down;
        function tipDownHandler(e)
        {
            // window.location.href='https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=KkhudvDE262krbQV9x04==&scene=110#wechat_redirect';
        }
        function bDownHandler(e)
        {

            e.data.originalEvent.stopImmediatePropagation();
            e.data.originalEvent.preventDefault();
            if(!page.bool_touch)
            {
                return;
            }
            TweenMax.killTweensOf(page.scroll);
            // page.scrolling=true;
            // downName= e.currentTarget.name;
            // bb_down=true;
            // bool_down=true;
            // sx=page.scroll.x;
            // mouseSX=e.data.global.x;
            // lastSX=e.data.global.x;
            // delta=0;

                if(e.currentTarget.name=='b0')
                {
                    var evt=new CustomEvent('Game_SubIn',{'detail':'0'})
                }
                else if(e.currentTarget.name=='b1')
                {
                    var evt=new CustomEvent('Game_SubIn',{'detail':'1'})
                }
                else if(e.currentTarget.name=='b2')
                {
                    var evt=new CustomEvent('Game_SubIn',{'detail':'2'})
                }
                document.dispatchEvent(evt);

        }
        var moveDetal=0;
        function bMoveHandler(e)
        {

            e.data.originalEvent.stopImmediatePropagation();
            e.data.originalEvent.preventDefault();
            // if(!page.bool_touch)
            // {
            //     return;
            // }
            // if(bb_down)
            // {
            //     moveDetal=e.data.global.x-mouseSX;
            //     page.scrolling=true;
            //     downName='';
            // }

        }
        function bUpHandler(e)
        {
            // page.scrolling=false;
            // e.data.originalEvent.stopImmediatePropagation();
            // e.data.originalEvent.preventDefault();
            // bb_down=false;
            // bool_down=false;
            // if(!page.bool_touch)
            // {
            //     return;
            // }
            // // if(downName!=''&&(downName== e.currentTarget.name))
            // if(Math.abs(moveDetal)<10)
            // {
            //     if(e.currentTarget.name=='b0')
            //     {
            //         var evt=new CustomEvent('Game_SubIn',{'detail':'0'})
            //     }
            //     else if(e.currentTarget.name=='b1')
            //     {
            //         var evt=new CustomEvent('Game_SubIn',{'detail':'1'})
            //     }
            //     else if(e.currentTarget.name=='b2')
            //     {
            //         var evt=new CustomEvent('Game_SubIn',{'detail':'2'})
            //     }
            //     document.dispatchEvent(evt);
            // }
        }


        function downHandler(e) {
            //e.data.originalEvent.stopImmediatePropagation();
            //e.data.originalEvent.preventDefault();
            // console.log(e.target.name);
            if(!page.bool_touch)
            {
                return;
            }
            page.scrolling=true;
            TweenMax.killTweensOf(page.scroll);
            bool_down=true;
            sx=page.scroll.x;
            mouseSX=e.data.global.x;
            lastSX=e.data.global.x;
            delta=0;
        }
        function moveHandler(e)
        {
            //e.data.originalEvent.stopImmediatePropagation();
            //e.data.originalEvent.preventDefault();
            if(!page.bool_touch)
            {
                return;
            }
            if(bool_down)
            {
                page.scrolling=true;
                page.scroll.x=sx+(e.data.global.x-mouseSX);
                delta=(e.data.global.x-lastSX);
                lastSX= e.data.global.x;
                if(page.scroll.x>0)
                {
                    page.scroll.x=0;
                }
                if(page.scroll.x<-page.scroll.width+1136)
                {
                    page.scroll.x=-page.scroll.width+1136;
                }
            }
        }
        function upHandler(e)
        {
            //e.data.originalEvent.stopImmediatePropagation();
            //e.data.originalEvent.preventDefault();
            bool_down=false;
            // page.scrolling=false;
            if(!page.bool_touch)
            {
                return;
            }

            // if(lastSX>3)
            // {
            //     TweenMax.to()
            // }
            TweenMax.killTweensOf(page.scroll);

            //if(downName!=''&&(downName== e.target.name))
            //{
            //    if(e.target.name=='b0')
            //    {
            //        var evt=new CustomEvent('Game_SubIn',{'detail':'0'})
            //    }
            //    else if(e.target.name=='b1')
            //    {
            //        var evt=new CustomEvent('Game_SubIn',{'detail':'1'})
            //    }
            //    else if(e.target.name=='b2')
            //    {
            //        var evt=new CustomEvent('Game_SubIn',{'detail':'2'})
            //    }
            //    document.dispatchEvent(evt);
            //}

            if(Math.abs(delta)<2)
            {
                delta=0;
            }
            else if(Math.abs(delta)>20)
            {
                if(delta>0)
                {
                    delta=20
                }
                else
                {
                    delta=-20
                }

            }
            TweenMax.to(page.scroll,0.5,{x:page.scroll.x+delta*30,onUpdate:function () {
                if(page.scroll.x>0)
                {
                    TweenMax.killTweensOf(page.scroll);
                    page.scroll.x=0;
                }
                if(page.scroll.x<-page.scroll.width+1136)
                {
                    TweenMax.killTweensOf(page.scroll);
                    page.scroll.x=-page.scroll.width+1136;
                }
            },onComplete:function () {
                page.scrolling=false;
            }});

        }

        return page;
    }
}